package top.tagao.multithread_02_use.exercise;

/**
 * @author fu-xiao-liu
 * @Date 2022/3/29 20:23
 * 创建三个窗口卖票，总票数为100张.使用实现Runnable接口的方式
 *  存在线程的安全问题，待解决。
 *
 */
public class ex02 {
    public static void main(String[] args) {
        WinRunnable winRun = new WinRunnable();
        Thread thread1 = new Thread(winRun);
        Thread thread2 = new Thread(winRun);
        Thread thread3 = new Thread(winRun);
        thread1.start();
        thread2.start();
        thread3.start();
    }
}


class WinRunnable implements Runnable{
    private  int ticket  = 100;
    @Override
    public void run() {
        while(true){
            if(ticket > 0){
                System.out.println(Thread.currentThread().getName() + ":卖票，票号为：" + ticket);
                ticket--;
            }else{
                break;
            }
        }
    }
}
